package com.example.demo.his.leetcode;

/**
 * @auther zzc
 * @date 2021/3/19 15:27
 */
public class 合并两个有序列表 {
    public static void main(String[] args) {
        ListNode l1 = new ListNode();
        ListNode l2 = new ListNode();

        mergeNodeLists(l1, l2);
    }

    private static ListNode mergeNodeLists(ListNode l1, ListNode l2) {
        if (l1 == null) {
            return l2;
        }
        if (l2 == null) {
            return l1;
        }
        if (l1.val < l2.val) {
            l1.next = mergeNodeLists(l1.next, l2);
            return l1;
        }
        if (l2.val < l1.val) {
            l2.next = mergeNodeLists(l2.next, l1);
            return l2;
        }
        return null;
    }



    //模拟一个链表
    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
